home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Amiga Plus 1995 #3 & #4
/
Amiga Plus CD - 1995 - No. 3 and 4.iso
/
pd
/
sound
/
cybersound
/
cdplayer
/
source
/
cliinterface.c
< prev
next >
Wrap
C/C++ Source or Header
|
1995-07-20
|
6KB
|
256 lines
/********************************************
* CD Audio Player using 14bit sound driver *
* for Toshiba 4101 CDRom and compatible *
* (c) 1995 by Christian Buchner *
********************************************
*
* CLIInterface.c
*/
/* Note: TAB SIZE = 4 */
/* Includes */
#include <proto/dos.h>
#include <proto/exec.h>
#include <libraries/dos.h>
#include <utility/tagitem.h>
#include <string.h>
/* Prototypes */
#include "CDPlayer_Protos.h"
void __saveds ProgramCallback(void);
BOOL ReadDefaults(void);
void FreeDefaults(void);
/* Externals */
extern struct DosLibrary *DOSBase; /* From CDPlayer.c */
extern void WBInterface(void); /* From WBInterface.c */
extern void GUI(void); /* From WBInterface.c */
/* Default parameters */
UBYTE DefaultDriverName[]="14bit.driver";
UBYTE DefaultSCSIName[]="scsi.device";
ULONG DefaultSCSIUnit=3;
ULONG DefaultFrequency=44100;
ULONG DefaultQuality=1;
ULONG DefaultBuffers=20;
/* Command line arguments */
UBYTE *Template="TRACKS/N/M,DEVICE/K,UNIT/N/K,SOUNDDRIVER/K,REPEAT/S,FREQUENCY/N,QUALITY/N,BUFFERS/N,HIGHPRI/S,PUBSCREEN/K,GUI/S";
struct ArgArray
{
ULONG **aa_Tracks;
UBYTE *aa_SCSIName;
ULONG *aa_SCSIUnit;
UBYTE *aa_SoundDriver;
ULONG aa_Repeat;
ULONG *aa_Frequency;
ULONG *aa_Quality;
ULONG *aa_Buffers;
ULONG aa_HighPri;
UBYTE *aa_PubScreen;
ULONG aa_GUI;
};
struct ArgArray AA;
struct RDArgs *RDArgs;
struct RDArgs *RDArgsSuccess;
struct RDArgs *GlobalRDArgs;
struct RDArgs *GlobalRDArgsSuccess;
/* Other variables */
struct Process *MyProc;
UBYTE LineBuffer[256];
UBYTE ErrorBuffer[100];
/*******************************************************************************/
/* CLI interface routine */
LONG __saveds main()
{
char ProgName[32];
ULONG Signals=0;
/* Get task pointer */
MyProc=(struct Process*)FindTask(NULL);
if (MyProc->pr_CLI == NULL)
{
WBInterface();
}
else
{
if (DOSBase=(struct DosLibrary*)OpenLibrary("dos.library",37))
{
if (!GetProgramName(ProgName,32L)) strcpy(ProgName,"CDPlayer");
/* Read global defaults */
if (ReadDefaults())
{
if (!(RDArgs=ReadArgs(Template,(LONG *)&AA,0)))
{
PrintFault(IoErr(),ProgName);
}
else
{
/* Set defaults for the arguments */
if (!AA.aa_SCSIName) AA.aa_SCSIName= DefaultSCSIName;
if (!AA.aa_SCSIUnit) AA.aa_SCSIUnit= &DefaultSCSIUnit;
if (!AA.aa_SoundDriver) AA.aa_SoundDriver= DefaultDriverName;
if (!AA.aa_Frequency) AA.aa_Frequency= &DefaultFrequency;
if (!AA.aa_Quality) AA.aa_Quality= &DefaultQuality;
if (!AA.aa_Buffers) AA.aa_Buffers= &DefaultBuffers;
if (AA.aa_GUI)
{
GUI();
}
else
{
if (InitDriver(AA.aa_SoundDriver,*AA.aa_Buffers))
{
if (OpenSCSI(AA.aa_SCSIName,*AA.aa_SCSIUnit,(BOOL)AA.aa_HighPri))
{
/* Create a program for replay */
if (!CD_SetProgram(AA.aa_Tracks, ProgramCallback))
{
Message("CD or specified track list contain no audio tracks.");
}
else
{
CD_Frequency(*AA.aa_Frequency);
CD_Quality (*AA.aa_Quality);
/* Start reading/playing */
CD_Start();
/* Loop forever (well, not quite) */
for (;;)
{
/* Wait for something to happen */
Signals=Wait(SIGBREAKF_CTRL_C|SIGBREAKF_CTRL_F);
/* Break out on CTRL-C */
if (Signals&SIGBREAKF_CTRL_C)
{
PrintFault(ERROR_BREAK,NULL);
break;
}
/* Program has finished, so exit */
if (Signals&SIGBREAKF_CTRL_F) break;
}
/* Abort playing */
CD_Abort();
}
CloseSCSI();
}
DeInitDriver();
}
FreeArgs(RDArgs);
}
FreeDefaults();
}
CloseLibrary((struct Library*)DOSBase);
}
}
}
return(0);
}
/* Callback routine for finished program */
void __saveds ProgramCallback(void)
{
/* Repeat desired? */
if (AA.aa_Repeat)
{
/* Restart playing */
CD_Start();
}
else
{
/* Signal main task about program end */
Signal((struct Task*)MyProc,SIGBREAKF_CTRL_F);
}
}
/* Read global defaults */
BOOL ReadDefaults(void)
{
ULONG LineLength;
BOOL Success=TRUE;
/* Try to read global defaults (environment variable) */
if (LineLength=GetVar("CD-DA_DEFAULTS", LineBuffer, sizeof(LineBuffer)-1, 0))
{
/* Append a linefeed or ReadArgs will complain */
strcat(LineBuffer,"\n");
LineLength++;
/* Allocate and initialize a RDArgs structure */
if (GlobalRDArgs=(struct RDArgs*)AllocDosObject(DOS_RDARGS,TAG_DONE))
{
GlobalRDArgs->RDA_Source.CS_Buffer=LineBuffer;
GlobalRDArgs->RDA_Source.CS_Length=LineLength;
GlobalRDArgs->RDA_Source.CS_CurChr=0;
GlobalRDArgs->RDA_DAList=NULL;
GlobalRDArgs->RDA_Buffer=NULL;
GlobalRDArgs->RDA_BufSiz=NULL;
GlobalRDArgs->RDA_ExtHelp=NULL;
GlobalRDArgs->RDA_Flags=RDAF_NOPROMPT;
/* Try to parse the string */
if (!(GlobalRDArgsSuccess=ReadArgs(Template, (LONG *)&AA, GlobalRDArgs)))
{
Fault(IoErr(),NULL, ErrorBuffer, sizeof(ErrorBuffer));
Message("Error parsing default options:\n%s%s",GlobalRDArgs->RDA_Source.CS_Buffer,ErrorBuffer);
Success=FALSE;
}
}
}
if (!Success)
{
memset(&AA, sizeof(AA), 0);
FreeDefaults();
}
return(Success);
}
/* Free global defaults */
void FreeDefaults()
{
if (GlobalRDArgsSuccess)
{
FreeArgs(GlobalRDArgsSuccess);
GlobalRDArgsSuccess=NULL;
}
if (GlobalRDArgs)
{
FreeDosObject(DOS_RDARGS, GlobalRDArgs);
GlobalRDArgs=NULL;
}
}